//
//  Mythread.m
//  8多线程
//
//  Created by zhengwei on 2/13/16.
//  Copyright © 2016 zhengwei. All rights reserved.
//

#import "Mythread.h"

@implementation Mythread
-(void)testThread{
//    1 NSThread:简单线程控制
//    1.1 当前线程的名称: num = 1 (主线程) name：main num != 1
    NSLog(@"%@",[NSThread currentThread]);
//    1.2 判断当前线程是否主线程
    NSLog(@"%d",[NSThread isMainThread]);
//    1.3 当前线程休眠: 精度有限
    NSLog(@"currentTime1");
    [NSThread sleepForTimeInterval:1];
    NSLog(@"currentTime2");
//    1.4 Creat
    NSThread *thread1 = [[NSThread alloc]initWithTarget:self selector:@selector(threadAction1) object:nil];
    thread1.name = @"hello";
    [thread1 start];
    [NSThread detachNewThreadSelector:@selector(threadAction2) toTarget:self withObject:nil];
}
-(void)threadAction1{
    NSLog(@"我是线程1 我启动了");
    NSLog(@"threadAction1 = %@",[NSThread currentThread]);
}
-(void)threadAction2{
    NSLog(@"我是线程2 我启动了");
    NSLog(@"threadAction2 = %@",[NSThread currentThread]);
//    [self performSelectorOnMainThread:@selector(<#selector#>) withObject:<#(nullable id)#> waitUntilDone:<#(BOOL)#>];
    [self performSelectorInBackground:@selector(threadAction3) withObject:nil];  //后台调用线程
}
-(void)threadAction3{
    NSLog(@"我是线程3 我启动了");
    NSLog(@"threadAction3 = %@",[NSThread currentThread]);
}
@end
